package vn.personal.anhht.bloback12.block;

import vn.personal.anhht.bloback12.activity.R;
import android.content.Context;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class PasswordReference extends DialogPreference{
    
    private View view;
    
    public PasswordReference(Context context, AttributeSet attrs) {
        super(context, attrs);
        
    }
    public PasswordReference(Context context, AttributeSet attrs, int i) {
        super(context, attrs, i);
        
    }
    @Override
    protected View onCreateDialogView() {
        
        View v = super.onCreateDialogView();
        this.view = v;
        return view;
    }

    @Override
    protected void onDialogClosed(boolean positiveResult) {
        
        super.onDialogClosed(positiveResult);
        EditText etPass = (EditText) view.findViewById(R.id.et_password_1);
        EditText etPassConfirm = (EditText) view.findViewById(R.id.et_password_2);
        if(positiveResult){ //press OK button
            String sPass = etPass.getText().toString().trim();
            String sPassConfirm = etPassConfirm.getText().toString().trim();
            if(sPassConfirm != null && sPassConfirm.equals(sPass)){
                setText(sPass);
                Toast.makeText(view.getContext(), R.string.toast_update_pass, Toast.LENGTH_LONG).show();
                //android.util.Log.e("fapplock_savepassword", sPass);
                return;
            }else{
                Toast.makeText(view.getContext(), R.string.toast_notthesame_pass, Toast.LENGTH_SHORT).show();
                showDialog(null);
                getDialog().setTitle(R.string.dialog_title_change_pass);
                return;
            }
        }
        return;
    }
    
    public void setText(String s){
        boolean flag = shouldDisableDependents();
        persistString(s);
        boolean flag2 = shouldDisableDependents();
        if(flag2 != flag){
        } else {
            notifyDependencyChange(flag2);
        }
        return;
    }
    
    
}